﻿
@{
    ViewData["Title"] = "添加文章分类";
}

<div class="row">
    <form id="ajaxForm" enctype="multipart/form-data" class="form-horizontal">
        <div class="container-fluid">
            <div class="row form-group">
                <label class="control-label col-md-2">分类名称</label>
                <div class="col-md-10">
                    <input class="form-control" name="category_name" id="category_name" type="text" />
                </div>
            </div>
            <div class="row form-group">
                <label class="control-label col-md-2">图片(400x400)</label>
                <div class="col-md-10">
                    <input class="form-control" name="img" id="img" type="file" placeholder="绝对路径,或者相对路径" accept="image/*"/>
                </div>
            </div>
            <div class="row form-group">
                <label class="control-label col-md-2">排序数字</label>
                <div class="col-md-10">
                    <input class="form-control" name="sort" id="sort" type="number" max="100" min="1" value="100" />
                </div>
            </div>
            <div class="row form-group">
                <label class="control-label col-md-2">是否显示</label>
                <div class="col-md-10">
                    <input class="i-checks" name="is_show" id="is_show" type="checkbox" value="true" />
                </div>
            </div>

            <div class="row form-group">
                <div class="col-md-6 col-md-offset-2">
                    <button type="button" class="btn btn-primary" onclick="SaveArticleCategory()">保存</button>
                </div>
            </div>
        </div>
    </form>
</div>

@section scripts{
    <script type="text/javascript">

        function SaveArticleCategory() {
            if ($("#category_name").val().length === 0) {
                utils.ShowError("请输入分类名称");
                return;
            }
            if ($("#img").val().length === 0) {
                utils.ShowError("请选择分类图标");
                return;
            }

            $("#ajaxForm").ajaxSubmit({
                type: 'post',
                url: '@Url.Action("Save")',
                data: {

                },  // data是作为额外提交的表单数据
                success: function (e) {
                    if (e.msg == 'ok') {
                        utils.ShowSuccess(e.data, function () {
                            location.href = '@Url.Action("list")';
                        });
                    }
                },
                error: function (e) {
                    utils.ShowError(e.data);
                }
            });
        }
    </script>
}